package com.ken.algorithms.tree;
import java.util.Scanner;

/**
 * <ul>
 * <li>Title: TreeUtil</li>
 * <li>Description: TODO </li>
 * </ul>
 *
 * @author 程序员ken
 * @date 2021-08-25 17:15
 */

public class TreeUtil {


    /***
     * 功能描述: 构建树的通用方法
     * @param scanner
     * @return: com.ken.algorithms.tree.TreeNode
     * @author: swc
     * @date: 2021-09-10 15:55
    */
    public static TreeNode createTreeNode(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");

        if (split.length < 3) {
            return null;
        }
        int val  = Integer.parseInt(split[0]);
        TreeNode treeNode = new TreeNode(val);

        if(Integer.parseInt(split[1])!=0){
            treeNode.setLeft(createTreeNode(scanner));
        }
        if(Integer.parseInt(split[2])!=0){
            treeNode.setRight(createTreeNode(scanner));
        }
        return treeNode;
    }



/*
    */
/***
     * 功能描述: 构建红黑树的通用方法
     * @param scanner
     * @return: com.ken.algorithms.tree.TreeNode
     * @author: swc
     * @date: 2021-09-10 15:55
     *//*

    public static RedBlackTree createRedBlackTreeNode(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");

        if (split.length < 3) {
            return null;
        }
        int val  = Integer.parseInt(split[0]);
        RedBlackTree treeNode = new RedBlackTree(val);

        if(Integer.parseInt(split[1])!=0){
            treeNode.setLeft(createTreeNode(scanner));
        }
        if(Integer.parseInt(split[2])!=0){
            treeNode.setRight(createTreeNode(scanner));
        }
        return treeNode;
    }
*/


}


